quartz: move utils to gdkutils-quartz.c
authorKristian Rietveld <kris@gtk.org>
Thu, 23 Dec 2010 12:14:49 +0000 (13:14 +0100)
committerKristian Rietveld <kris@gtk.org>
Thu, 23 Dec 2010 13:17:41 +0000 (14:17 +0100)
gdk/quartz/Makefile.am
gdk/quartz/gdkcursor-quartz.c
gdk/quartz/gdkevents-quartz.c
gdk/quartz/gdkutils-quartz.c [new file with mode: 0644]

index cfbe55d9cb30f8e7d35c710fa7d9eb6bd95d507d..b9c5b464fa30198c63d149214ea223f44639e885 100644 (file)
@@ -42,6 +42,7 @@ libgdk_quartz_la_SOURCES =            \
        gdkscreen-quartz.h      \
        gdkselection-quartz.c   \
        gdktestutils-quartz.c   \
+       gdkutils-quartz.c       \
        gdkvisual-quartz.c      \
        gdkwindow-quartz.c      \
        gdkwindow-quartz.h      \
index 7f3e142833f5473a6916f55a29fcf5cba9763467..22b7676acba44af4d82b230d82064442889148f7 100644 (file)
@@ -250,70 +250,6 @@ _gdk_quartz_display_get_cursor_for_type (GdkDisplay    *display,
   return gdk_quartz_cursor_new_from_nscursor (nscursor, cursor_type);
 }
 
-static NSImage *
-_gdk_quartz_pixbuf_to_ns_image (GdkPixbuf *pixbuf)
-{
-  NSBitmapImageRep  *bitmap_rep;
-  NSImage           *image;
-  gboolean           has_alpha;
-  
-  has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
-  
-  /* Create a bitmap image rep */
-  bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL 
-                                         pixelsWide:gdk_pixbuf_get_width (pixbuf)
-                                        pixelsHigh:gdk_pixbuf_get_height (pixbuf)
-                                        bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
-                                        hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
-                                        bytesPerRow:0 bitsPerPixel:0];
-       
-  {
-    /* Add pixel data to bitmap rep */
-    guchar *src, *dst;
-    int src_stride, dst_stride;
-    int x, y;
-               
-    src_stride = gdk_pixbuf_get_rowstride (pixbuf);
-    dst_stride = [bitmap_rep bytesPerRow];
-               
-    for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++) 
-      {
-       src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
-       dst = [bitmap_rep bitmapData] + y * dst_stride;
-       
-       for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
-         {
-           if (has_alpha)
-             {
-               guchar red, green, blue, alpha;
-               
-               red = *src++;
-               green = *src++;
-               blue = *src++;
-               alpha = *src++;
-               
-               *dst++ = (red * alpha) / 255;
-               *dst++ = (green * alpha) / 255;
-               *dst++ = (blue * alpha) / 255;
-               *dst++ = alpha;
-             }
-           else
-            {
-              *dst++ = *src++;
-              *dst++ = *src++;
-              *dst++ = *src++;
-            }
-         }
-      }        
-  }
-       
-  image = [[NSImage alloc] init];
-  [image addRepresentation:bitmap_rep];
-  [bitmap_rep release];
-  [image autorelease];
-       
-  return image;
-}
 
 GdkCursor *
 _gdk_quartz_display_get_cursor_for_pixbuf (GdkDisplay *display,
@@ -330,7 +266,7 @@ _gdk_quartz_display_get_cursor_for_pixbuf (GdkDisplay *display,
 
   has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
 
-  image = _gdk_quartz_pixbuf_to_ns_image (pixbuf);
+  image = gdk_quartz_pixbuf_to_ns_image_libgtk_only (pixbuf);
   nscursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(x, y)];
 
   cursor = gdk_quartz_cursor_new_from_nscursor (nscursor, GDK_CURSOR_IS_PIXMAP);
@@ -432,9 +368,3 @@ gdk_quartz_cursor_get_image (GdkCursor *cursor)
   /* FIXME: Implement */
   return NULL;
 }
-
-NSImage *
-gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
-{
-  return _gdk_quartz_pixbuf_to_ns_image (pixbuf);
-}
index 3b20df2886b294c5963bfb9efc3d2b5698989ad1..227cdbdb948a2b4486add528c85847a4afee952e 100644 (file)
@@ -55,13 +55,6 @@ static int          current_button_state;
 static void append_event                        (GdkEvent  *event,
                                                  gboolean   windowing);
 
-NSEvent *
-gdk_quartz_event_get_nsevent (GdkEvent *event)
-{
-  /* FIXME: If the event here is unallocated, we crash. */
-  return ((GdkEventPrivate *) event)->windowing_data;
-}
-
 void
 _gdk_quartz_events_init (void)
 {
diff --git a/gdk/quartz/gdkutils-quartz.c b/gdk/quartz/gdkutils-quartz.c
new file mode 100644 (file)
index 0000000..122a31c
--- /dev/null
@@ -0,0 +1,99 @@
+/* gdkutils-quartz.c
+ *
+ * Copyright (C) 2005 Imendio AB
+ * Copyright (C) 2010  Kristian Rietveld  <kris@gtk.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <AppKit/AppKit.h>
+
+#include <gdkquartzutils.h>
+#include "gdkprivate-quartz.h"
+
+NSImage *
+gdk_quartz_pixbuf_to_ns_image_libgtk_only (GdkPixbuf *pixbuf)
+{
+  NSBitmapImageRep  *bitmap_rep;
+  NSImage           *image;
+  gboolean           has_alpha;
+  
+  has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+  
+  /* Create a bitmap image rep */
+  bitmap_rep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL 
+                                         pixelsWide:gdk_pixbuf_get_width (pixbuf)
+                                        pixelsHigh:gdk_pixbuf_get_height (pixbuf)
+                                        bitsPerSample:8 samplesPerPixel:has_alpha ? 4 : 3
+                                        hasAlpha:has_alpha isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
+                                        bytesPerRow:0 bitsPerPixel:0];
+       
+  {
+    /* Add pixel data to bitmap rep */
+    guchar *src, *dst;
+    int src_stride, dst_stride;
+    int x, y;
+               
+    src_stride = gdk_pixbuf_get_rowstride (pixbuf);
+    dst_stride = [bitmap_rep bytesPerRow];
+               
+    for (y = 0; y < gdk_pixbuf_get_height (pixbuf); y++) 
+      {
+       src = gdk_pixbuf_get_pixels (pixbuf) + y * src_stride;
+       dst = [bitmap_rep bitmapData] + y * dst_stride;
+       
+       for (x = 0; x < gdk_pixbuf_get_width (pixbuf); x++)
+         {
+           if (has_alpha)
+             {
+               guchar red, green, blue, alpha;
+               
+               red = *src++;
+               green = *src++;
+               blue = *src++;
+               alpha = *src++;
+               
+               *dst++ = (red * alpha) / 255;
+               *dst++ = (green * alpha) / 255;
+               *dst++ = (blue * alpha) / 255;
+               *dst++ = alpha;
+             }
+           else
+            {
+              *dst++ = *src++;
+              *dst++ = *src++;
+              *dst++ = *src++;
+            }
+         }
+      }        
+  }
+       
+  image = [[NSImage alloc] init];
+  [image addRepresentation:bitmap_rep];
+  [bitmap_rep release];
+  [image autorelease];
+       
+  return image;
+}
+
+NSEvent *
+gdk_quartz_event_get_nsevent (GdkEvent *event)
+{
+  /* FIXME: If the event here is unallocated, we crash. */
+  return ((GdkEventPrivate *) event)->windowing_data;
+}